<template>
  <div>
    <BaseDialog :visible.sync="isDealer" :title="'经销商查询'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <OwnerSeacher @close="emitCloseHandler1" />
    </BaseDialog>
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle"></TopFilter>

    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :selectionType="'single'"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="columns => (this.columns = columns)"
    >
    </FilterTable>
    <div style="height:47px;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>
      <el-button @click="closeDrawer(2)" type="primary" :disabled="selectList.length < 1">确 定</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { vehicleConfiguration } from '@/api/omFinance';
import { queryReportInfo } from '@/api/omSale/SalesReturn/ReturnApplication/index.js';
import OwnerSeacher from '../OwnerSeacher';
export default {
  mixins: [dictionary],
  data() {
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: queryReportInfo,
      fetchParams: {
        vehicleStatus: 60401004
      },
      selectList: [],
      isDealer: false,
      dealerCode: ''
    };
  },
  components: {
    OwnerSeacher
  },
  created() {
    this.getList();
  },
  methods: {
    async getList() {
      let res = await vehicleConfiguration(0, { isUnlimited: 10041001 });
      this.topFilterList.find(item => item.fieldName === 'vehicleInfo').itemList = res.data;
    },
    createdFrom() {
      return [
        {
          type: 'INPUT_CASCADER',
          label: '车型选择',
          fieldName: 'vehicleInfo',
          placeholder: '请选择',
          options: { titles: ['品牌', '车系', '车型', '配置', '选装', '颜色'] },
          itemList: []
        },
        {
          type: 'SELECT',
          label: '车辆状态',
          fieldName: 'vehicleStatus',
          initialValue: 60401004,
          placeholder: '请选择',
          itemList: this.createDictList('6040').filter(x => x.value == 60401004)
        },
        {
          type: 'INPUT',
          label: 'VIN码',
          fieldName: 'vin',
          placeholder: '请输入'
        },
        // {
        //   type: 'INPUT',
        //   label: '产品名称',
        //   fieldName: 'productName',
        //   placeholder: '请输入'
        // },
        {
          type: 'INPUT',
          label: '经销商名称',
          fieldName: 'dealerName',
          placeholder: '请选择',
          readonly: true,
          unitRender: () => {
            return (
              <div>
                <el-button icon="el-icon-search" onClick={() => this.dealerHandle()}></el-button>
              </div>
            );
          }
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '零售订单号',
          dataIndex: 'orderNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: 'VIN码',
          dataIndex: 'vin',
          align: 'center',
          width: 180,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品名称',
          dataIndex: 'productName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车辆状态',
          dataIndex: 'vehicleStatus',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6040').filter(x => x.value == 60401004),
          render: p => {
            return <span>{this.createDictText(p.row.vehicleStatus, '6040')}</span>;
          }
        },
        {
          title: '实销通过日期',
          dataIndex: 'reportDate',
          sorter: true,
          filter: true,
          filterType: 'input',
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '客户名称',
          dataIndex: 'customerName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户手机号',
          dataIndex: 'mobile',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户类型',
          dataIndex: 'customerType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1523'),
          render: p => {
            return <span>{this.createDictText(p.row.customerType, '1523')}</span>;
          }
        },
        {
          title: '订单价格',
          dataIndex: 'salesQuatation',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    changeHandle(val) {
      val.vehicleStatus = 60401004;
      this.fetchParams = Object.assign({}, this.fetchParams, val);
    },
    closeDrawer(type) {
      if (type == 1) {
        this.$emit('close');
      } else {
        this.$emit('close', this.selectList);
      }
    },
    emitCloseHandler1(val, data) {
      this.isDealer = val;
      if (data) {
        let dealerCodes = [];
        let dealerNames = [];
        data.map(x => {
          dealerCodes.push(x.dealerCode);
          dealerNames.push(x.dealerName);
        });
        this.dealerCode = dealerCodes.toString();
        this.topFilterList.find(x => x.fieldName == 'dealerName').initialValue = dealerNames.toString();
      }
    },
    dealerHandle() {
      this.isDealer = true;
    },
    selectChangeHandle(val) {
      this.selectList = val || [];
    }
  }
};
</script>
